package cn.micro.eye.web;

import cn.micro.eye.commons.auth.PreAuth;
import cn.micro.eye.model.add.MemberAdd;
import cn.micro.eye.model.dto.MemberCategoryCount;
import cn.micro.eye.model.edit.MemberEdit;
import cn.micro.eye.model.query.MemberPageQuery;
import cn.micro.eye.model.vo.MemberInfoVO;
import cn.micro.eye.model.vo.MemberPageVO;
import cn.micro.eye.model.vo.MemberSearchVO;
import cn.micro.eye.service.IMemberService;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 用户基础信息 前端控制器
 * </p>
 *
 * @author lry
 * @since 2018-09-11
 */
@PreAuth
@Validated
@RestController
@RequestMapping("member")
public class MemberController {

    @Resource
    private IMemberService memberService;

    @RequestMapping(value = "info", method = RequestMethod.GET)
    public MemberInfoVO info() {
        return memberService.info();
    }

    @RequestMapping(value = "category-count", method = RequestMethod.GET)
    public List<MemberCategoryCount> categoryCount() {
        return memberService.categoryCount();
    }

    @RequestMapping(value = "page", method = RequestMethod.POST)
    public Page<MemberPageVO> page(@RequestBody @Validated MemberPageQuery memberPageQuery) {
        return memberService.searchPage(memberPageQuery);
    }

    @RequestMapping(value = "{id}", method = RequestMethod.GET)
    public MemberPageVO get(@PathVariable("id") Long id) {
        return memberService.get(id);
    }

    @RequestMapping(method = RequestMethod.DELETE)
    public Boolean delete(@RequestBody List<Long> ids) {
        return memberService.delete(ids);
    }

    @RequestMapping(value = "edit", method = RequestMethod.PUT)
    public Boolean edit(@RequestBody @Validated MemberEdit memberEdit) {
        return memberService.edit(memberEdit);
    }

    @RequestMapping(value = "add", method = RequestMethod.POST)
    public Boolean add(@RequestBody @Validated MemberAdd memberAdd) throws Exception {
        return memberService.add(memberAdd);
    }

    @RequestMapping(value = "search/{openId}", method = RequestMethod.GET)
    public List<MemberSearchVO> search(@PathVariable("openId") String openId) {
        return memberService.search(openId);
    }

}
